import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

export let indexchildren = [
  {
    path: '/index/home',
    name: 'index/home',
    title: "首页",
    icon:"wap-home-o",
    component: () => import(/* webpackChunkName: "about" */ '../views/index/Home.vue'),
  },
  {
    path: '/index/classity',
    name: 'index/classity',
    title: "分类",
    icon:"apps-o",
    component: () => import(/* webpackChunkName: "about" */ '../views/index/Classity.vue'),
  },
  {
    path: '/index/my',
    name: 'index/my',
    title: "我的",
    icon:"contact",
    meta: {//路由元信息
      neddLogin: true// 路由标记为需要登录, 自定义
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/index/My.vue'),
  },
  {
    path: '/index/xing/:id',
    name: 'index/xing',
    title: "详情",
    icon:"contact",
    meta: {//路由元信息
      neddLogin: true// 路由标记为需要登录, 自定义
    },
    component: () => import(/* webpackChunkName: "about" */ '../views/index/Xing.vue'),
  }
]


const routes = [
  {
    path: '/',
    redirect: '/index/home',  // 重定向:重新指向其它path,会改变网址
  },
  {
    path: '/index',
    name: 'index',
    component: () => import(/* webpackChunkName: "about" */ '../views/Index'),
    children: indexchildren
  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 访问的白名单, 可以直接通行

// router.beforeEach((to, from, next) => {
//   // 访问的路径在白名单
//   if (to.meta.neddLogin && !window.localStorage.getItem("token")) {
//     next("/login")
//   } else {
//     next()
//   }
// })
export default router
